#include <windows.h>
#include <memory>
#include "loader.h"

using namespace std;
static unique_ptr<HydraLoader> s_loader;

BOOL APIENTRY DllMain( HMODULE hModule,
					  DWORD  ul_reason_for_call,
					  LPVOID lpReserved
					  )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		{
			if(!s_loader)
            {
                s_loader.reset(new HydraLoader());

                // load CRL 4.0 CP
                if(!s_loader->isHost())
                {
                    s_loader->loadCLR();
                }
            }
			break;
		}
	case DLL_THREAD_ATTACH: break;
	case DLL_THREAD_DETACH: break;
	case DLL_PROCESS_DETACH:
		{
			if(!s_loader)
            {
                // unload CLR 4.0 CP
                delete s_loader.release();
            }
			break;
		}
	}
	return TRUE;
}
